$(document).ready(function () {
  /* 设置第一张图片 */
  $(".slider .bd li").first().before($(".slider .bd li").last());

  /* 滚动切换 */
  $(".slider").slide({
    titCell: ".hd ul",
    mainCell: ".bd ul",
    effect: "leftLoop",
    autoPlay: true,
    vis: 3,
    autoPage: true,
    trigger: "mouseover",
  });
});
//
//
//
var hei = document.querySelector(".hei");
window.onscroll = function (e) {
  var winhei = window.pageYOffset;
  if (winhei >= 30) {
    hei.style.height = "0px";
  } else {
    hei.style.height = "30px";
  }
};
//
//
//
var viewpage = document.getElementsByClassName("viewpage")[0];
var calList = document.getElementsByClassName("cal-list")[0];
var items = document.getElementsByClassName("items");
var prev = document.getElementsByClassName("prev")[0];
var next = document.getElementsByClassName("next")[0];
var circles = document.getElementsByClassName("circle");
var circleList = document.getElementsByClassName("circle-list")[0];
// 1 自动轮播
var index = 0;
var imgIndex = 0;
var interId1;
function autoplay() {
  interId1 = setInterval(function () {
    index++;
    imgIndex++;
    if (index >= items.length) {
      index = 1;
      viewpage.style.left = "0px";
    }
    if (imgIndex == circles.length) {
      imgIndex = 0;
    }
    initColor(circles);
    circles[imgIndex].className = "circle active";

    var target = -600 * index;
    slowMoveAnima(viewpage, target);
  }, 2000);
}
autoplay();

//2 鼠标悬停暂停, 离开继续
calList.onmouseover = circleList.onmouseover = function (e) {
  prev.style.display = "block";
  next.style.display = "block";
  clearInterval(interId1);
};
//鼠标离开继续
calList.onmouseout = circleList.onmouseout = function (e) {
  prev.style.display = "none";
  next.style.display = "none";
  autoplay();
};
//3 左右按钮
next.onclick = function (e) {
  index++;
  imgIndex++;
  if (index == items.length) {
    index = 1;
    viewpage.style.left = "0px";
  }
  if (imgIndex == circles.length) {
    imgIndex = 0;
  }
  initColor(circles);
  circles[imgIndex].className = "circle active";

  var target = -600 * index;
  slowMoveAnima(viewpage, target);
};
prev.onclick = function (e) {
  if (index == 0) {
    index = items.length - 1;
    viewpage.style.left = -600 * index + "px";
  }
  index--;
  imgIndex--;
  if (imgIndex < 0) {
    imgIndex = circles.length - 1;
  }
  initColor(circles);
  circles[imgIndex].className = "circle active";
  var target = -600 * index;
  slowMoveAnima(viewpage, target);
};

// 排他函数
function initColor(eles) {
  for (var j = 0; j < eles.length; j++) {
    eles[j].className = "circle";
  }
}

for (var i = 0; i < circles.length; i++) {
  circles[i].ind = i;
  circles[i].onmouseover = function (e) {
    index = this.ind;
    imgIndex = this.ind;
    initColor(circles);
    circles[imgIndex].className = "circle active";
    var target = -600 * index;
    slowMoveAnima(viewpage, target);
  };
}
//
//
//
var foot1LiI = document.querySelectorAll(".foot_1_li>i");
for (var i = 0; i < 5; i++) {
  foot1LiI[i].style.backgroundPosition = "" + i * -34 + "px    0px";
}
